package com.example.month11.vp_tab;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.example.month11.vp_tab.fragment.SplashFragment;
import com.example.month11.vp_tab.view.ScaleTransformer;
import com.example.recyclerview01.R;

/**
 * 左右滑动，引导页。
 */
public class SplashActivity extends AppCompatActivity {

    private ViewPager mViewPager;
    private int[] mResIds = new int[]{
            R.drawable.loading_bg,
            R.drawable.welcome_guide_01,
            R.drawable.welcome_guide_02,
            R.drawable.welcome_guide_03};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        mViewPager = findViewById(R.id.id_viewpager);
        // FragmentStatePagerAdapter能更好的管理内存。
        mViewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return SplashFragment.newInstance(mResIds[position]);
            }

            @Override
            public int getCount() {
                return mResIds.length;
            }
        });

        // 左右tab切换，添加动画。切换与动画解耦性做的很好。
        mViewPager.setPageTransformer(true, new ScaleTransformer());
    }
}